package com.mdd.cms.controller.security;

import com.mdd.cms.params.SecurityStudioParams;
import com.mdd.cms.service.security.SecurityStudioService;
import com.mdd.cms.vo.SecurityStudioDetailVo;
import com.mdd.cms.vo.SecurityStudioListVo;
import com.mdd.cms.vo.security.SecurityStudioSearchValidate;
import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validate.AddGroup;
import com.mdd.common.validate.EditGroup;
import com.mdd.common.validate.IdValidate;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 安全学习
 *
 * @Description
 * @Author 幻速
 * @Date 2024/1/30 10:36
 **/
@RestController
@RequestMapping("api/system/security")
@Api(tags = "安全学习管理")
public class SysSecurityStudioController {
    @Resource
    SecurityStudioService securityStudioService;

    /**
     * 查询内容列表
     * @param searchValidate 查询参数
     * @return 返回查询内容
     */
    @GetMapping("/pages")
    public AjaxResult<PageResult<SecurityStudioListVo>> pages(@Validated SecurityStudioSearchValidate searchValidate,
                                                              @Validated PageValidate pageValidate){
        return AjaxResult.success(securityStudioService.pages(pageValidate,searchValidate.getKeyWorld()));
    }
    /**
     * 根据sid查询内容
     * @param sid 安全学习内容
     * @return 安全学习详情
     */
    @GetMapping("/detail")
    public AjaxResult<SecurityStudioDetailVo> detail(@Validated @IDMust() @RequestParam("id") Long sid){
        return AjaxResult.success(securityStudioService.getDetail(sid));
    }
    /**
     * add 添加安全学习内容
     * @param securityStudioParams 安全学习内容
     * @return 添加结果
     */
    @PostMapping("/add")
    public AjaxResult<Object> add(@Validated(AddGroup.class) @RequestBody SecurityStudioParams securityStudioParams){
        return AjaxResult.success(securityStudioService.add(securityStudioParams));
    }
    /**
     * 更新内容
     * @param securityStudioParams 更新内容
     */
    @PostMapping("/update")
    public AjaxResult<Object> update(@Validated(EditGroup.class) @RequestBody SecurityStudioParams securityStudioParams){
        return AjaxResult.success(securityStudioService.update(securityStudioParams));
    }
    @NotPower
    @Log(title = "内容删除")
    @PostMapping("/del")
    @ApiOperation(value="内容删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        securityStudioService.del(idValidate.getId());
        return AjaxResult.success();
    }
}
